import * as vscode from "vscode";
import { 文本前部空格数量计算 } from "../ctsUtils/utils";
import { Command } from "../../../utils/commandManager";


export class 插入分部完成文本命令_ implements Command {
    public static readonly ID = 'ctsscript.插入分部完成文本命令_';
    public readonly ID = 插入分部完成文本命令_.ID;

    public execute(插入文本: string) {
        let 文档 = vscode.window.activeTextEditor!.document;
        let 行 = vscode.window.activeTextEditor!.selection.anchor.line;
        let 行文本 = 文档.lineAt(行).text;
        let 字符 = vscode.window.activeTextEditor!.selection.anchor.character;
        let 字符串文本 = 行文本.substring(0, 字符)
        let 前部空格数 = 文本前部空格数量计算(字符串文本);
        vscode.window.activeTextEditor!.edit(e => {
            e.replace(new vscode.Range(new vscode.Position(行, 字符 - 前部空格数), vscode.window.activeTextEditor!.selection.anchor), 插入文本)
        }).then(_ => {
            vscode.window.activeTextEditor!.selection = new vscode.Selection(vscode.window.activeTextEditor!.selection.active, vscode.window.activeTextEditor!.selection.active);
        });
    }
}
